package com.aeon.ui;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

public class TabFolderComposite extends Composite {

	private TabFolder mFolder;

	public TabFolderComposite(Composite parent, int style) {
		super(parent, style);

		setLayout(new FillLayout());

		mFolder = new TabFolder(this, SWT.BORDER_SOLID);

		TabItem item1 = createItem("item1");

		TabItem item2 = createItem("item2");
		TabItem item3 = createItem("item3");
		TabItem item4 = createImageItem("ImageTab");

	}

	private TabItem createImageItem(String string) {
		TabItem item = new TabItem(mFolder, SWT.BORDER_DOT);
		Composite composite2=new  Composite(mFolder, SWT.NONE);
		item.setText(string);
		item.setControl(composite2);
		composite2.setLayout(new FillLayout());
		
		ScrolledComposite scrolledComposite=new ScrolledComposite(composite2, SWT.H_SCROLL | SWT.V_SCROLL );
		scrolledComposite.setLayout(new FillLayout());
		scrolledComposite.setAlwaysShowScrollBars(true);
		
		Composite composite = new Composite(scrolledComposite,SWT.None);
		scrolledComposite.setContent(composite);

		composite.setLayout(new GridLayout(3, true));
		addlabel(composite, "It's me thumnail1",
				"E:\\funPlace\\swt\\SWT\\src\\com\\aeon\\ui\\label\\img\\book1.GIF");
		addlabel(composite, "It's me thumnail1",
				"E:\\funPlace\\swt\\SWT\\src\\com\\aeon\\ui\\label\\img\\book1.GIF");

		addlabel(composite, "It's me thumnail1",
				"E:\\funPlace\\swt\\SWT\\src\\com\\aeon\\ui\\label\\img\\book1.GIF");

		composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
		return item;
	}

	private void addlabel(Composite composite, String text, String imgPath) {
		CLabel label = new CLabel(composite, SWT.WRAP|SWT.BORDER_SOLID);
		label.setEnabled(true);
		label.setToolTipText(text);
		ImageData image = new ImageData(imgPath);
		ImageDescriptor descriptor = ImageDescriptor.createFromImageData(image
				.scaledTo(50, 50));
		label.setImage(descriptor.createImage());
		label.setText(text);
	}

	private TabItem createItem(String string) {
		TabItem item1 = new TabItem(mFolder, SWT.BORDER_DOT);
		item1.setText(string);
		Composite composite = new Composite(mFolder, SWT.BORDER_DOT);
		composite.setLayout(new FillLayout());

		item1.setControl(composite);
		Button button = new Button(composite, SWT.PUSH);

		button.setText(string);
		return item1;
	}

}
